package main

import (
	"downloader/cmd"
	"fmt"
	"io"
	"net/http"
	"os"
	"sync"
)

func main() {
	return
	if err := cmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
}

func test1() {
	// 由于 NewCDNChecker 未定义，这里假设它是从某个包导入的函数，
	// 以下示例假设从 "downloader/cdnchecker" 包导入，需要根据实际情况调整

}
func test2() {
	var wg sync.WaitGroup

	for i := 0; i < 10; i++ {

		wg.Add(1)
		go func(wg *sync.WaitGroup) error {
			urlStr := "https://spp875.jmxxu.cn/static/index/public/js/swiper.min.js"
			fmt.Println(urlStr)
			defer wg.Done()
			clent := &http.Client{}
			req, err := http.NewRequest("GET", urlStr, nil)
			if err != nil {
				fmt.Println(err)
				return err
			}
			// req.Header.Set("User-Agent", "Mozilla/5.0 (Linux; Android 9; PBEM00 Build/PKQ1.190519.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.62 XWEB/2691 MMWEBSDK/200901 Mobile Safari/537.36 MMWEBID/4773 MicroMessenger/7.0.19.1760(0x27001335) Process/toolsmp WeChat/arm64 NetType/4G Language/zh_CN ABI/arm64")
			// req.Header.Set("accept-encoding", "gzip, deflate, br, zstd")
			// req.Header.Set("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7")
			// req.Header.Set("sec-ch-ua", "\"\"")
			// req.Header.Set("sec-ch-ua-mobile", "?1")
			// req.Header.Set("sec-ch-ua-platform", "\"\"")
			// req.Header.Set("sec-fetch-dest", "document")
			// req.Header.Set("sec-fetch-mode", "navigate")
			// req.Header.Set("sec-fetch-site", "none")
			// req.Header.Set("sec-fetch-user", "?1")
			// req.Header.Set("upgrade-insecure-requests", "1")
			// req.Header.Set("sec-ch-ua", "\"\"")
			// req.Header.Set("sec-ch-ua-mobile", "?1")
			// req.Header.Set("sec-ch-ua-platform", "\"\"")

			resp, respErr := clent.Do(req)
			if respErr != nil {
				fmt.Println(respErr)
				return respErr
			}
			defer resp.Body.Close()
			body, err := io.ReadAll(resp.Body)
			if err != nil {
				fmt.Println(err)
				return err
			}
			// 原代码尝试将 nil 和字符串相加，这是无效操作。这里直接返回包含 body 内容的错误信息
			fmt.Println(resp.StatusCode)
			return fmt.Errorf("response body: %s", string(body))
			// bodyStr := string(body)
			// fmt.Printf(bodyStr)
			// downloader := core.NewDownloader(nil) // 可以传入配置
			// downloader.Download(urlStr)
			// savname := "temp/" + indexStr + ".html"
			// os.WriteFile(savname, []byte(bodyStr), 0644)
		}(&wg)

	}
	fmt.Println("All downloads doing")
	wg.Wait()
	fmt.Println("All downloads completed......................")

}
